package com.swotplus.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;

/**
 * 代码生成器
 * @author hugang
 * @since 2020-04-12
 */
public class MainGenerator {

    // 根据命名规范，只修改此常量值即可
    private static String MODULE = "";
    private static String TABLE_PREFIX = "";
    private static String PARENT_PACKAGE_NAME = "com.swotplus.system.weixin";

    private static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    private static String JDBC_URL = "jdbc:mysql://127.0.0.1:3306/swotplus?useUnicode=true&amp;characterEncoding=UTF-8&amp;tinyInt1isBit=false";
    private static String JDBC_USERNAME = "root";
    private static String JDBC_PASSWORD = "123456";

    private static String OUTPUT_DIR = "D:\\IdeaProjects\\swotplus\\src\\main\\java";
    //需生成数据库表名
    private static  String[] TABLE_LIST ={"wxcms_account","wxcms_account_fans","wxcms_account_menu","wxcms_account_menu_group","wxcms_article","wxcms_img_resource","wxcms_media_files","wxcms_msg_base","wxcms_msg_news","wxcms_msg_news_combin","wxcms_msg_text","wxcms_tpl_msg_text","wxcms_user_tag"};

    /**
     * 自动代码生成
     * @param args
     */
    public static void main(String[] args) {

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName(JDBC_DRIVER);
        dsc.setUsername(JDBC_USERNAME);
        dsc.setPassword(JDBC_PASSWORD);
        dsc.setUrl(JDBC_URL);

        PackageConfig pc = new PackageConfig();
        pc.setParent(PARENT_PACKAGE_NAME);
        pc.setModuleName(MODULE);

        DefaultGenerator defaultGenerator = new DefaultGenerator();
        defaultGenerator.setDataSource(dsc);
        defaultGenerator.setPackageInfo(pc);
        defaultGenerator.setIncludeTables(TABLE_PREFIX,TABLE_LIST);

        // 生成API
        defaultGenerator.setOutputDir(OUTPUT_DIR);
        defaultGenerator.createClass(
                "entity"
                ,"service"
                ,"Mapper"
                , "mapper"
                , "service.impl"
                ,"controller"
        );
//        // 生成服务
//        defaultGenerator.setOutputDir();
//        defaultGenerator.createClass(
//                "Mapper"
//                , "mapper"
//                , "service.impl"
//        );
//        // 生成Controller
//        defaultGenerator.setOutputDir();
//        defaultGenerator.createClass("controller");
    }

}
